/*******************************************************************************
																				
	DESCRIPTION: 	This do file cleans the predictions coming out of R, obtains the ensemble
					model, performs the last calibration step and saves the final 
					dataset, like 003_1, but for the predictions for X months generated using 
					a model trained at Y months.
	
*******************************************************************************/

clear all
global id_code 003

* Import the cleaning program:
do  "${code}/Data Management/003_0_CleaningPredictions_program.do"

*******************************************************************************
** Baseline, all years  **
*******************************************************************************

* Set outcomes:
global outcomes emplAft6M_0M_In emplAft6M_0M_In ///
	emplAft6M_6M_In emplAft6M_6M_In ///
	emplAft6M_12M_In emplAft6M_12M_In
global outcomes_sample emplAft6M_6M_In emplAft6M_12M_In ///
	emplAft6M_0M_In emplAft6M_12M_In ///
	emplAft6M_0M_In emplAft6M_6M_In


* Set models and year span:
global models Full
			
global yearSpan 1992/2016

foreach model in $models  {
		
		foreach year of numlist $yearSpan {
								
					di "Cleaning `model' `year' Model, `year_indiv' sample"
					cleanpred, model(`model') year(`year') outcomes(${outcomes}) ///
						outcomes_sample(${outcomes_sample}) ///
						name("_xMonthPred_yMonthModel")
					
		}
}


*******************************************************************************
** Baseline, pooled models  **
*******************************************************************************

* Set outcomes:
global outcomes emplAft6M_0M_In emplAft6M_0M_In ///
	emplAft6M_6M_In emplAft6M_6M_In ///
	emplAft6M_12M_In emplAft6M_12M_In
global outcomes_sample emplAft6M_6M_In emplAft6M_12M_In ///
	emplAft6M_0M_In emplAft6M_12M_In ///
	emplAft6M_0M_In emplAft6M_6M_In


* Set models and year span:
global models Full_Pooled
			
global yearSpan 2006_2007 2009_2010

foreach model in $models  {
		
		foreach year in $yearSpan {
								
					di "Cleaning `model' `year' Model, `year_indiv' sample"
					cleanpred, model(`model') year(`year') outcomes(${outcomes}) ///
						outcomes_sample(${outcomes_sample}) ///
						name("_xMonthPred_yMonthModel")
					
		}
}

*******************************************************************************
** Basic model, 2006  **
*******************************************************************************

* Set outcomes:
global outcomes emplAft6M_0M_In emplAft6M_0M_In ///
	emplAft6M_6M_In emplAft6M_6M_In ///
	emplAft6M_12M_In emplAft6M_12M_In
global outcomes_sample emplAft6M_6M_In emplAft6M_12M_In ///
	emplAft6M_0M_In emplAft6M_12M_In ///
	emplAft6M_0M_In emplAft6M_6M_In


* Set models and year span:			
cleanpred, model(Full_SeqDrop_incIndiv) year(2006) outcomes(${outcomes}) ///
	outcomes_sample(${outcomes_sample}) ///
	name("_xMonthPred_yMonthModel")

*******************************************************************************
** Model without recalls, 2006  **
*******************************************************************************

* Set outcomes:
global outcomes emplAft6M_0M_In emplAft6M_0M_In ///
	emplAft6M_6M_In emplAft6M_6M_In ///
	emplAft6M_12M_In emplAft6M_12M_In
global outcomes_sample emplAft6M_6M_In emplAft6M_12M_In ///
	emplAft6M_0M_In emplAft6M_12M_In ///
	emplAft6M_0M_In emplAft6M_6M_In


* Set models and year span:			
cleanpred, model(Full_NoRecalls) year(2006) outcomes(${outcomes}) ///
	outcomes_sample(${outcomes_sample}) ///
	name("_xMonthPred_yMonthModel") ///
	w_if(recalled == 0)

	